package com.vancouver.knows.business.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.bean.BannerInfo;
import com.vancouver.knows.business.bean.CityNewsDetailInfo;
import com.vancouver.knows.business.bean.CommentInfo;
import com.vancouver.knows.business.bean.RelatedPostInfo;

/**
 * 查询城事详情解析
 * <p/>
 * Created by cxlin
 */
public class FetchCityNewsDetailHandler extends ACheckableJsonParser {

	private CityNewsDetailInfo cityNewsDetailInfo;

	@Override
	protected void parserContent(JSONObject content) throws Exception {
		String posts = content.getString("post_details");
		cityNewsDetailInfo = JSON.parseObject(posts, CityNewsDetailInfo.class);
		String relatedPosts = content.getString("related_posts");
		if (!StringUtil.isEmptyString(relatedPosts)) {
			List<RelatedPostInfo> relatedPostInfoList = JSON.parseArray(relatedPosts, RelatedPostInfo.class);
			cityNewsDetailInfo.setRelatedPostInfoList(relatedPostInfoList);
		}
		String banner = content.getString("ad_banner");
		if (!StringUtil.isEmptyString(banner)) {
			cityNewsDetailInfo.setAdBanner(JSON.parseObject(banner, BannerInfo.class));
		}
		String hotComments = content.getString("hot_comments");
		if (!StringUtil.isEmptyString(hotComments)) {
			List<CommentInfo> commentInfoList = JSON.parseArray(hotComments, CommentInfo.class);
			cityNewsDetailInfo.setCommentInfoList(commentInfoList);
		}
	}

	public CityNewsDetailInfo getCityNewsDetailInfo() {
		return cityNewsDetailInfo;
	}

}
